package alogrithm;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/10/18 19:43
 */
public class OddEvenList {
    public ListNode oddEvenList(ListNode head) {
        // write code here
        ListNode dummyNode = new ListNode(-1);
        ListNode cur = dummyNode;
        ListNode p = head;
        while (p != null) {
            if ((p.val & 1) == 1) {
                cur.next = p;
                cur = cur.next;
            }
            p = p.next;
        }
        p = head;
        while (p != null) {
            if ((p.val & 1) == 0) {
                cur.next = p;
                cur = cur.next;
            }
            p = p.next;
        }
        return dummyNode.next;
    }

    public class ListNode {
        int val;
        ListNode next = null;

        public ListNode(int val) {
            this.val = val;
        }
    }
}
